//
//  DMBalanceDetailVC.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/16.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMBalanceDetailVC.h"
#import "FDSlideBar.h"
#import "DMBalanceDetailCell.h"
#import "DMBalanceDetailSecondCell.h"

@interface DMBalanceDetailVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UILabel *balanceLb;
@property (weak, nonatomic) IBOutlet UIView *headView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) FDSlideBar *sliderBar;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation DMBalanceDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self startInit];
}

-(void)startInit {
    
    NSArray *arr = @[@"奖金",@"余额",@"提成"];
    self.navigationItem.title = [NSString stringWithFormat:@"%@详情",arr[_flag]];
    self.view.backgroundColor = DMDefaultColor;
    _dataArray = [NSMutableArray new];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"DMBalanceDetailCell" bundle:nil] forCellReuseIdentifier:@"DMBalanceDetailCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DMBalanceDetailSecondCell" bundle:nil] forCellReuseIdentifier:@"DMBalanceDetailSecondCell"];
    //头部选择View
    [self makeSlideBar];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return _dataArray.count;
    return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section%2 == 0) {
        if (indexPath.section == 0) {
            return 140;
        }
        return 113;
    }
    return 169;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        DMBalanceDetailSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMBalanceDetailSecondCell" forIndexPath:indexPath];
        if (cell == nil) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"DMBalanceDetailSecondCell" owner:self options:nil].firstObject;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    DMBalanceDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMBalanceDetailCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"DMBalanceDetailCell" owner:self options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

//头部选择View
-(void)makeSlideBar {
    _sliderBar = [[FDSlideBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 45)];
    _sliderBar.itemsTitle = @[@"全部", @"近一个月", @"近三个月", @"近半年"];
    _sliderBar.backgroundColor = [UIColor clearColor];
    _sliderBar.itemColor = DMFontColor;
    _sliderBar.itemSelectedColor = DMMainColor;
    _sliderBar.sliderColor = DMMainColor;
    [_sliderBar selectSlideBarItemAtIndex:0];
    [_sliderBar slideBarItemSelectedCallback:^(NSUInteger idx) {
        //选择,刷新tableView
        //        _index = idx;
        //
    }];
    [_headView addSubview:_sliderBar];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 44, ScreenWidth, 1)];
    line.backgroundColor = RGBCOLOR(237, 237, 237);
    [_headView addSubview:line];
}

@end
